
/* usbn960x.c
* Copyright (C) 2005  Benedikt Sauter
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef _USBN960X_H
#define _USBN960X_H

//////////////////////////////////////////////////////////////////////////////

#ifndef O_USB_TINY
#define O_USB_TINY			0
#endif

//////////////////////////////////////////////////////////////////////////////

#ifdef ALL_IN_ONE
#include "usbn960xreg.h"
#include "usb11spec.h"
#else
#include "../usbn960xreg.h"
#include "../usb11spec.h"
#endif

/*-------------------------------------------
 * global data structs
 * ------------------------------------------*/

typedef void rxfunc_t (uint8_t *buf);

struct RxFIFOCaller
{
	uint8_t	  epadr;
	rxfunc_t *func;
};

typedef void txfunc_t (void);

struct TxFIFOCaller
{
	uint8_t	  epadr;
	txfunc_t *func;
};

typedef struct functioninfo FunctionInfo;
struct functioninfo
{
//  uint8_t Address;
	uint8_t ConfigurationIndex;
};

typedef struct devicereq DeviceRequest;
struct devicereq
{
	uint8_t  bmRequestType;
	uint8_t  bRequest;
	uint16_t wValue;
	uint16_t wIndex;
	uint16_t wLength;
};

typedef struct epinfo EPInfo;
struct epinfo
{
	uint8_t  usbnData;
	uint8_t  usbnCommand;
	uint8_t  usbnControl;
	uint8_t  DataPid;			// 0 = data0, 1 = data1
	uint8_t  Sending;
	uint16_t usbnfifo;
	uint16_t Index;
	uint16_t Size;
	uint16_t SizeExp;			// size expected by the device
	const uint8_t *Buf;
};

//////////////////////////////////////////////////////////////////////////////
// global variables !!

struct RxFIFOCaller rxfifos [4];

//#if !O_USB_TINY
struct TxFIFOCaller txfifos [4];
//#endif

//////////////////////////////////////////////////////////////////////////////
// global functions

/// start usb system after configuration
void    USBNStart (void);

// system functions
void    USBNInterrupt (void);

void    USBNTransmitFIFO1 (int length, uint8_t *answer);
#if O_USB_TINY
void    USBNCallbackFIFO_RX1 (rxfunc_t *fct);
#endif

//////////////////////////////////////////////////////////////////////////////
// only for compiler

// usbn2mc.c
extern void USBNDecodeVendorRequest (DeviceRequest * req);
extern void USBNDecodeClassRequest (DeviceRequest * req);

extern void USBNDebug (const char *msg);
extern void USBNDebug_P (const char *msg);
extern void USBNDebugHex (uint8_t);

extern uint8_t USBNRead (uint8_t Adr);
extern void USBNReadBuf (uint8_t Adr, uint8_t len, uint8_t *buf);

extern void USBNWrite (uint8_t Adr, uint8_t Data);
extern void USBNWriteBuf (uint8_t Adr, uint8_t len, const uint8_t *buf);

// main.c
//extern void  USBNInterfaceRequests (DeviceRequest *req, EPInfo *ep);

//extern const uint8_t *UsbGetDeviceDescriptor (void);
//extern const uint8_t *UsbGetConfigDescriptor (uint8_t index);
//extern const uint8_t *UsbGetString (uint8_t index);

//////////////////////////////////////////////////////////////////////////////

#endif /* __USBN960X_H__ */
